﻿using System;
using System.Linq;
using BITS.PreCompiler.CSharp.Syntax;
using BITS.PreCompiler.CSharp.Semantic.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace BITS.PreCompiler.CSharp.Tests.Semantic
{
    [TestClass]
    public class TestDeclaredSymbol
    {
        [TestMethod]
        public void Using()
        {
            // Arrange
            var @class = new Class("ClassX");
            var using1 = new Using<String>();
            var using2 = new Using<IQueryable>();
            var module = new Module("XTest.A.B");

            module.Namespace.Add(@class);
            module.Add(using1);
            module.Add(using2);

            
            // Asset
            var sematicModel = module.GetSemanticModel();

            var aliasSymbol = sematicModel.GetDeclaredSymbol(using2);


            // Assure
            Assert.AreEqual(using1.Name, aliasSymbol.ToString());
        }

        [TestMethod]
        public void Namespace_Of_Class_Within_Module()
        {
            // Arrange
            var module = new Module
            {
                new Namespace("XTest.A.B")
                {
                    new Class("ClassX")
                }
            };

            // Asset
            var sematicModel = module.GetSemanticModel();

            var namedTypeSymbol = sematicModel.GetDeclaredSymbol(
                module.Namespace.Classes.Single());

            var @ns = new Module
            {
                new Namespace("XTest.A.B")
                {
                    new Class("ClassX")
                }
            }
            .GetSemanticModel()
            .GetDeclaredSymbol(module.Namespace.Classes.Single())
            .ContainingNamespace;

            // Assure
            Console.WriteLine(namedTypeSymbol.ContainingNamespace.ToString());
            Assert.AreEqual(module.Namespace.Name, namedTypeSymbol.ContainingNamespace.ToString());
        }

        [TestMethod]
        public void Namespace_Of_Method_Within_Module()
        {
            // Arrange
            var @method = new Method("Method");
            var @class = new Class("ClassX");
            var module = new Module("XTest.A.B");

            @class.Add(@method);
            module.Namespace.Add(@class);


            // Asset
            var sematicModel = module.GetSemanticModel();

            var methodSymbol = sematicModel.GetDeclaredSymbol(@method);


            // Assure
            Assert.AreEqual(module.Namespace.Name, methodSymbol.ContainingNamespace.ToString());
        }
    }
}
